package com.enen.controller;

import com.enen.anno.LogOperation;
import com.enen.pojo.*;
import com.enen.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    // 分页查询学员信息
    @GetMapping
    public Result findAll(StudentQueryParam studentQueryParam){
        log.info("班级分页查询{}",studentQueryParam);
        PageResult<Student> pageResult = studentService.findAll(studentQueryParam);
        return Result.success(pageResult);

    }

    // 添加学员信息
    @LogOperation
    @PostMapping
    public Result save(@RequestBody Student student){
        log.info("添加学员信息{}",student);
        studentService.save(student);
        return Result.success();
    }

    // 根据id查询学员信息
    @GetMapping("/{id}")
    public Result geiInfo(@PathVariable Integer id){
        log.info("根据id查询班级信息{}",id);
        Student student = studentService.getInfo(id);
        return Result.success(student);

    }
    // 根据id删除学员信息
    @LogOperation
    @DeleteMapping("/{ids}")
    public Result delect(@PathVariable List<Integer> ids){
        log.info("根据id批量删除学员:{}",ids);
        studentService.delect(ids);
        return Result.success();
    }

    // 修改学员信息
    @LogOperation
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改学员信息{}",student);
        studentService.update(student);
        return Result.success();
    }

    // 违纪处理
    @LogOperation
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id,@PathVariable Integer score){
        log.info("违规{}{}",id,score);
        studentService.violation(id,score);
        return Result.success();
    }
}
